package com.example.zzm.yuejian03.Activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zzm.yuejian03.Bean.TrainBean;
import com.example.zzm.yuejian03.Listener.TListener;
import com.example.zzm.yuejian03.Model.TrainModeldetails;
import com.example.zzm.yuejian03.R;
import com.example.zzm.yuejian03.Server;
import com.squareup.picasso.Picasso;

public class TraindetailsActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageView imageView12;
    private TextView textView11,textView28,textView30,textView32,textView34,textView36,textView38;
    private Button button12;
    private Context Context;
    private int userid;
    private SharedPreferences sp;
    private int resid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_traindetails);

        sp = getSharedPreferences("userInfo",MODE_PRIVATE);
        userid = sp.getInt("user_id",1);
        resid  = getIntent().getIntExtra("train_id",1);
        initViews();
        initEvent();
        TrainModeldetails TrainModeldetails = new TrainModeldetails();
        TrainModeldetails.getTraindetailss(getIntent().getIntExtra("train_id",1),listener);

        //resid  = getIntent().getIntExtra("club_id",1);
    }

    TListener<TrainBean> listener = new TListener<TrainBean>() {
        @Override
        public void onResponse(final TrainBean club) {
            textView28.setText(club.getTrain_name());
            textView30.setText(club.getIntro());
            textView38.setText(Integer.toString(club.getPrice()));
            textView32.setText(club.getTime());
            textView34.setText(club.getAddress());
            textView36.setText(Integer.toString(club.getTel()));
            Picasso.with(TraindetailsActivity.this)
                    .load(Server.IMAGEURL + club.getPic())
                    .placeholder(R.mipmap.ic_launcher)
                    // .memoryPolicy(MemoryPolicy.NO_CACHE)
                    .into(imageView12);
            button12.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent=new Intent(TraindetailsActivity.this, BaominActivity.class);
                    intent.putExtra("train_id",club.getid());
                    startActivity(intent);
                }
            });
        }
        @Override
        public void onFail(String msg) {

        }
    };

    private void initViews(){
        textView28 = (TextView)findViewById(R.id.textView28);//mingc
        textView30 = (TextView)findViewById(R.id.textView30);//jieshao
        textView32= (TextView)findViewById(R.id.textView32);//jiaolian
        textView34 = (TextView)findViewById(R.id.textView34);
        textView36 = (TextView)findViewById(R.id.textView36);
        textView38 = (TextView)findViewById(R.id.textView38);
        imageView12=(ImageView)findViewById(R.id.imageView12);
        textView11 = (TextView) findViewById(R.id.textView11);//fanhui
        button12 = (Button)findViewById(R.id.button12);
    }

    private void initEvent(){
        textView11.setOnClickListener(this);
        button12.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.textView11:
                finish();
                break;
        }
    }

}
